using System;
using Crosstales.FB;
using UnityEngine;
using UnityEngine.UI;

public class PathSelect : MonoBehaviour
{
    /// <summary>
    /// 选择按钮
    /// </summary>
    private Button btn_select;
    /// <summary>
    /// 路径输入框
    /// </summary>
    private InputField input_path;
    /// <summary>
    /// 选择框标题
    /// </summary>
    public string title;

    protected void Awake()
    {
        btn_select = transform.Find("btn_select").GetComponent<Button>();
        input_path = transform.Find("input_path").GetComponent<InputField>();

        btn_select.onClick.AddListener(SelectDir);
    }

    /// <summary>
    /// 获取路径
    /// </summary>
    public string GetPath()
    {
        return input_path.text;
    }

    /// <summary>
    /// 设置路径
    /// </summary>
    public void SetPath(string path)
    {
        input_path.text = path;
    }

    /// <summary>
    /// 选择目录
    /// </summary>
    public void SelectDir()
    {
        // 选择目录
        string path = Crosstales.FB.FileBrowser.Instance.OpenSingleFolder(title);
        if (!String.IsNullOrEmpty(path))
        {
            input_path.text = path;
        }
    }

    /// <summary>
    /// 打开目录
    /// </summary>
    public void OpenDir()
    {
        // 选择目录
        string path = input_path.text;
        if (!String.IsNullOrEmpty(path))
        {
            path = path.Replace('/', '\\');
            Crosstales.Common.Util.FileHelper.ShowPath(path);
        }
    }
}
